package com.e_manager.soft.emanager.util;

import com.tencent.xinge.Message;
import com.tencent.xinge.MessageIOS;
import com.tencent.xinge.XingeApp;
import org.json.JSONObject;


public class XingeUtils {
//    /**信鸽android accessid*/
//    public static final Long ANDROID_SUPPLY_ACCESS_ID = 2100278062L;
//
//    /**信鸽android secretkey*/
//    public static final String ANDROID_SUPPLY_SECRET_KEY = "7f51f6fa5d0b1469d37da03627c8e94a";
//
//    /**安卓推送*/
//    public static final String ANDROID_DEVICE = "a";

    /**
     * 安卓单个设备推送
     * @param title
     * @param content
     * @param token
     */
    public static JSONObject pushTokenAndroid(Long accessId,String secretKey,String title , String content, String token,int MessageType,String dev){
        //自定义推送
        XingeApp xinge = new XingeApp(accessId, secretKey);
        Message message = new Message();
        MessageIOS remoteMessageIOS = new MessageIOS();
        JSONObject ret;
        if("android".equals(dev)) {
            message.setTitle(title);
            if(MessageType==0) {
                message.setType(Message.TYPE_MESSAGE);
                message.setContent(content);
            }else {
                message.setType(Message.TYPE_NOTIFICATION);
                message.setContent("请点击查看！");
            }
            ret = xinge.pushSingleDevice(token, message);
        }else{
            if(MessageType==0) {
                remoteMessageIOS.setAlert(title);
                remoteMessageIOS.setType(Message.TYPE_MESSAGE);
                remoteMessageIOS.setCustom(JsonUtil.jsonToMap(content));
            }else {
                remoteMessageIOS.setAlert("请点击查看！");
                remoteMessageIOS.setType(Message.TYPE_NOTIFICATION);
                remoteMessageIOS.setCustom(JsonUtil.jsonToMap(content));
            }
            ret = xinge.pushSingleDevice(token, remoteMessageIOS, xinge.IOSENV_DEV);
        }
        return ret;
    }
    /**
     * 安卓全设备推送
     * @param title
     * @param content
     * @return
     */
    public static JSONObject pushAllAndroid(Long accessId,String secretKey,String title,String content){
        return XingeApp.pushAllAndroid(accessId, secretKey, title, content);
    }


//    public static void main(String[] args) {
//        //安卓推送
//        XingeApp.pushTokenAndroid(ANDROID_SUPPLY_ACCESS_ID, ANDROID_SUPPLY_SECRET_KEY, "有一条信息需要处理", "测试信鸽", "8be7654b1cdcdffc4e75bdcfbd70edbe80f59dbd");
//        XingeApp xinge = new XingeApp(ANDROID_SUPPLY_ACCESS_ID, ANDROID_SUPPLY_SECRET_KEY);
//        Message message = new Message();
//        message.setTitle("有一条信息需要处理");
//        message.setContent("测试信鸽");
//        message.setType(Message.TYPE_MESSAGE);
//        JSONObject ret = xinge.pushSingleDevice("8be7654b1cdcdffc4e75bdcfbd70edbe80f59dbd", message);
//        XingeApp.pushAllAndroid(ANDROID_SUPPLY_ACCESS_ID,ANDROID_SUPPLY_SECRET_KEY,"有一条信息需要处理","测试信鸽全部");
//        System.out.println("aaa");
//    }
}
